package com.ms.teapuesto.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 */
@Aspect
@Component("DaoAspect")
public class DaoAspect {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @PostConstruct
    public void init() {

    }

    @Pointcut("bean(*DAOImpl)")
    private void jsfBean() {

    }

    @Around("jsfBean())")
    public Object logAllMethodsPainterAndTeacher(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        String method = proceedingJoinPoint.getSignature().toShortString();
        try {
//            logger.debug("Around: Before executing:" + method);
            Object obj = proceedingJoinPoint.proceed();
//            logger.debug("Around: After executing:" + method);
            return obj;
        } catch (Throwable throwable) {
            logger.error("Problemas llamado al metodo: " + method, throwable);
            return null;
        }
    }
}
